//Accepted
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <map>
using namespace std;

int  rep[200001];
int rank[200001];
int  sum[200001];

void _make_set(int x){
	rep[x]=x;
	rank[x]=0;
}

int _find_set(int x){
	if(x!=rep[x])
		rep[x]=_find_set(rep[x]);
	return rep[x];
}

void _link(int x, int y){
	if(rank[x]>rank[y]){
		sum[x]+=sum[y];
		rep[y] = x;
	}
	else{
		sum[y]+=sum[x];
		rep[x]=y;
		if(rank[x]==rank[y]){
			rank[y]++;
		}
	}
}

void _union(int x, int y){
	_link(_find_set(x),_find_set(y));
}


int t, n;
map<string,int> m;
string a, b;
int x, y, i;


int main (){
	//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
	
	scanf("%d", &t);
	while(t--){
		scanf("%d", &n);
		i=1;
		m.clear();
		while(n--){
			cin>>a>>b;
			x=m[a];
			y=m[b];
			if(!x){
				x=m[a]=i++;
				_make_set(x);
				sum[x]=1;
			}
			if(!y){
				y=m[b]=i++;
				_make_set(y);
				sum[y]=1;
			}
			
			if(_find_set(x)==_find_set(y)){
				printf("%d\n", sum[rep[x]]);
			}
			else{
				_union(x,y);
				printf("%d\n", sum[_find_set(x)]);
			}
		}
	}
	return 0;
}
